/*
 * @Author: your name
 * @Date: 2021-08-31 10:45:46
 * @LastEditTime: 2021-09-04 15:58:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day07\3-查找数据.js
 */


//indexof lastIndexof 通过数据项的值去查找在数据中的索引位置 比较的是恒等于===

var arr = [100, 200, 300, 100, 200, 300, 400];
var r1 = arr.indexOf(100); //0
var r2 = arr.indexOf(100, 2); //3
var r3 = arr.indexOf(600) //-1
var r4 = arr.lastIndexOf(100) //3
console.log(r1, r2, r3, r4);
var r5 = arr.indexOf('100'); //-1
console.log(r5);

var ob = { name: 'fff', age: 12 };
var arr1 = [{
        name: 'zs',
        age: 10,
        toString: function() {
            return 'a';
        },
        valueOf: function() { return -1 }
    },
    { name: 'lisi', age: 18 },
    { name: 'ww', age: 20 },
    ob

];

var r6 = arr1.indexOf({
    name: 'zs',
    age: 10,
    toString: function() {
        return 'a';
    },
    valueOf: function() { return -1 }
});
console.log(r6); //-1   查找不到
var r7 = arr1.indexOf(ob);
console.log(r7); //3  注意对象ob的位置，要先定义对象再把它放到数组里，否则查找不到